package com.github.thinwonton.showcase.groovy.introduce;

import groovy.lang.Binding;
import groovy.lang.GroovyClassLoader;
import org.apache.commons.io.IOUtils;
import org.codehaus.groovy.runtime.InvokerHelper;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * JavaRunGroovyDemo
 *
 * @author hugo
 * @date 2019/10/31
 */
public class JavaRunGroovyDemo {
    public static void main(String[] args) {
        Binding context = new Binding();
        context.setVariable("name", "hello groovy");
        GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
        String groovyScript = "println name";
        Class scriptClass = groovyClassLoader.parseClass(groovyScript);
        Object obj = InvokerHelper.createScript(scriptClass, context).run();
    }

}
